import random
import time
from collections import deque


# from exam3_extra_resource_main import my_list_for_bubble, my_list_for_binary, keys




my_list_for_bubble = [
    42, 17, 33, 85, 61, 49, 95, 24, 73, 10, 50, 99, 21, 62, 78, 90, 12, 36, 57, 63,
    88, 7, 3, 56, 68, 75, 15, 11, 97, 8, 28, 46, 31, 29, 93, 70, 6, 38, 94, 23, 65,
    52, 40, 18, 81, 9, 32, 14, 59, 26, 2, 48, 83, 25, 20, 37, 84, 4, 77, 66, 64, 27,
    92, 35, 13, 41, 60, 80, 22, 30, 5, 34, 86, 98, 55, 67, 19, 43, 47, 1, 44, 71, 87,
    54, 100, 79, 96, 16, 45, 74, 91, 76, 58, 39, 72, 51, 82, 89, 53, 69,
    17, 36, 53, 44, 78, 25, 89, 5, 23, 60, 91, 100, 33, 66, 8, 29, 40, 3, 11, 92,
    57, 80, 54, 72, 35, 47, 7, 21, 1, 46, 12, 62, 99, 87, 9, 26, 41, 39, 30, 34, 84,
    95, 56, 85, 64, 27, 50, 74, 98, 48, 79, 77, 63, 16, 37, 81, 22, 6, 32, 45, 52,
    43, 68, 31, 20, 70, 13, 38, 67, 73, 75, 59, 94, 4, 28, 61, 18, 42, 24, 14, 2,
    17, 36, 53, 44, 78, 25, 89, 5, 23, 60, 91, 100, 33, 66, 8, 29, 40, 3, 11]

my_list_for_binary = [_ for _ in range(1, 10001)]

keys = ["hello", "world", "python", "is", "awesome", "cow", "dog", "cat", "bird", "fish"]





step = 0


def naive_search(a,b):
    my_array=random.randint(a,b)
    #The Naive Search
    start_time_naive = time.time()
    for i in range(a,b+1):
        if i==my_array:
            print(i,"is the answer")
            end_time_naive = time.time()
            print("Time taken (The Naive Search): {:.6f} seconds".format(end_time_naive - start_time_naive))
            break

def binary_search(a,b, step):
    start_time_binary = time.time()
    my_array=random.randint(a,b)
    maybe=0
    Result=False
    up=b
    down=a
    while Result!=True:
        step += 1
        maybe=(up+down)//2
        if maybe==my_array:
            print(f"bingo,the number is {maybe}")
            break
        elif maybe>my_array:
            s
            up=maybe
        elif maybe<my_array:
            down=maybe
        print(f"step {step}:[{my_list_for_binary[up]} {my_list_for_binary[down]}]")
    end_time_binary = time.time()
    print("Time taken (The Binary Search): {:.6f} seconds".format(end_time_binary-start_time_binary))

def selection(numbers):
    sum=len(numbers)
    for i in range(sum):
        min=i
        for j in range(i+1,sum):
            if numbers[j]<numbers[min]:
                min=j
        numbers[i],numbers[min]=numbers[min],numbers[i]
    return numbers

#bubble_sort
def bubble_sort(numbers, step):
    sum=len(numbers)
    for i in range(sum-1):
        for j in range(sum-1-i):
            if numbers[j]>numbers[j+1]:
                step += 1
                print(f"step {step}:{my_list_for_bubble[j]} and {my_list_for_bubble[j+1]} switched !")
                numbers[j],numbers[j+1]=numbers[j+1],numbers[j]
    return numbers
def learn_id():
    print("Learn_ID:         5")
    list_of_numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    list_id = id(list_of_numbers)
    print("List:", list_of_numbers)
    print("Memory Address of the List:", list_id)

def learn_deque():
    print("Learn_Deque:      6")
    my_groceries = deque()
    my_groceries.append("potato")
    my_groceries.append("carrot")
    my_groceries.append("mango")
    my_groceries.append("strawberry")
    print("My Groceries:", my_groceries)
    item = my_groceries.pop()
    print("Popped item from right:", item)
    print("My Groceries after popping from right:", my_groceries)
    item = my_groceries.popleft()
    print("Popped item from left:", item)
    print("My Groceries after popping from left:", my_groceries)
    my_groceries.appendleft("apple")
    print("My Groceries after appending left:", my_groceries)
    my_groceries.append("banana")
    print("My Groceries after appending right:", my_groceries)

bubble_sort(my_list_for_bubble, step)
step = 0
binary_search(my_list_for_binary, step)

# if __name__ == '__main__':
#     test1=[random.randint(0,1000) for i in range(10)]
#     test2=[random.randint(0,10000) for i in range(10)]
#     test3=[random.randint(0,100000) for i in range(10)]
#     test4=[random.randint(0,1000) for i in range(10)]
#     test5=[random.randint(0,10000) for i in range(10)]
#     test6=[random.randint(0,100000) for i in range(10)]
#     #naive_search
#     print("Naive_search:     1")
#     naive_search(1, 1000)
#     naive_search(1, 10000)
#     naive_search(1, 100000)
#     #binary_search
#     print("Binary_search:    2")
#     binary_search(1, 1000)
#     binary_search(1, 10000)
#     binary_search(1, 100000)
#     #selection_sort
#     print("Selection_Sort:   3")
#     print(test1)
#     print(selection(test1))
#     print(test2)
#     print(selection(test2))
#     print(test3)
#     print(selection(test3))
#     #bubble_sort
#     print("Bubble_Sort:      4")
#     print(test4)
#     print(bubble_sort(test4))
#     print(test5)
#     print(bubble_sort(test5))
#     print(test6)
#     print(bubble_sort(test6))
#     learn_id()
#     learn_deque()

   




    
